<?php
namespace app\pay\controller;
use think\Input;
class Api extends Common{
    public function initialize(){
        parent::initialize();
    }
    // 商城码商通道列表
    public function channels(){  
        header('Access-Control-Allow-Origin:*');
        if(request()->isGet()){
            $shopid =input('shopid')?input('shopid'):0; 
            $appid =input('appid')?input('appid'):0; 
            $sign =input('sign')?input('sign'):0;
            if($shopid && $appid && $sign){
                $shop=db('shop')->where(array('id'=>$shopid,'appid'=>$appid,'open'=>1))->find();
                if($shop){  
                    $signrel=strtoupper(md5($shop['appid'].$this->sys['version']));
                    if($sign===$signrel){
                        $list=db('channel')->where('shopid',$shopid)->where('shopappid',$appid)->where('open',1)->where('state',0)->orderRand()->limit('1')
                            ->field('id as channelid,shopid,shopname,cionname,title,price,userid as uuid')->select();
                        if($list){
                            $payinfo=db('user_banks')->where('userid',$list[0]['uuid'])->where('open',1)->field('name,name_en,id as bankid,bank_name')->select();  
                            $payurl=$this->sys['url'].url('pay/pay/index');
                            $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'payinfo'=>$payinfo,'rel'=>1,'payurl'=>$payurl];
                        }else{
                            $result = ['code'=>-1,'msg'=>'暂未开放!'];
                        }
                    }else{
                        $result = ['code'=>-1,'msg'=>'签名错误!'];
                    }
                }else{
                    $result = ['code'=>-1,'msg'=>'商户不存在!'];
                }
            }else{
            	$result = ['code'=>-1,'msg'=>'信息不全!'];
            }
            return json($result);
        }
    }     
}  